package com.summerrain.colnect.jsouplib;

import java.io.IOException;
import java.util.ArrayList;

import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class GetAllCatgs {
	public static ArrayList<String> getAllCategories() {
		ArrayList<String> data = new ArrayList<String>();
		try {
			Response response = Jsoup
					.connect(
							"http://colnect.com/en/")
					/*.userAgent(
							"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")*/
					//.userAgent("Mozilla")
					//.timeout(10000)
							.execute();
			
			
			String resp = response.body();
			Document doc = Jsoup.parse(resp);			
			Elements cats = doc.getElementById("categories_box_full").getElementsByClass("category_box");
			String tmp = "";
			for (Element src : cats) {
				tmp = "http://colnect.com"+src.select("div > a").attr("href") + "@"+src.select("div > a > img").attr("src")+"@"+src.select("div > h1 > a").text()+"@";
				tmp +=src.select("div > p").first().text();
				data.add(tmp);
			}
			
			
		} catch (IOException e) {
			e.printStackTrace();
		}		
		return data;
	}
	
}
